/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GameObject;

import java.awt.Graphics2D;
import java.awt.Image;
import java.io.File;
import java.io.IOException;
import java.util.Timer;
import javax.imageio.ImageIO;

/**
 *
 * @author NGUYEN VAN TAM
 */
public class Effect extends VisibleGameEntity{
    
    public boolean show;
    
    @Override
    public boolean Init(int _numberSprite[], int _Width,int _Heigth,String StrResource[],int isprite, int _nDelay)
    {
        show = false;
        _nsprite = _numberSprite.length;
        _sprite = new Sprite[_nsprite];
        this.width = _Width;
        this.height = _Heigth;
        this.nDelay = _nDelay;
        this.show = false;
        
        for (int i = 0; i < _nsprite; i++)
        {
            try
            {
                Image[] image = new Image[_numberSprite[i]];

                for (int j = 0; j < _numberSprite[i]; j++)
                {
                    image[j] = ImageIO.read(new File(StrResource[i] + j + ".png"));
                }
                _sprite[i] = new Sprite(0, 0, _Width,_Heigth ,image);
                _isprite = isprite;
            }
            catch(IOException ex)
            {
                return false;
            }
        }
        return true;
    }
    
    @Override
    public VisibleGameObject Clone()
    {
        VisibleGameObject obj = new Effect();
        obj._nsprite = this._nsprite;
        obj.x = this.x;
        obj.y = this.y;
        obj._isprite = this._isprite;
        obj.width = this.width;
        obj.height = this.height;
        ((Effect)obj).show = false;
        obj.nDelay = this.nDelay;
        
        for(int i = 0;i < this._sprite.length;i++)
        {
            obj._sprite[i] = new Sprite(this.x, this.y, this._sprite[i]._width, this._sprite[i]._height, this._sprite[i]._images);
        }
        return obj;
    }
    
    @Override
    public void Update(Timer gameTime)
    {
        this.Update(gameTime);
    }
    
    @Override  
    public void Update(Timer gameTime,int x, int y, int w, int h)
    {
        if(nDelay == 0)
        {
            this.width = w;
            this.height = h;
            this.x = x;
            this.y = y;
            
            for (int i = 0; i < _sprite.length; i++)
            {
                _sprite[i].update(gameTime,x,y,w,h,_sprite[i]._selectedIndex);
            }
        }
        else 
        {
            nDelay--;
        }
    }
    
    public void SetShow(boolean _show)
    {
        this.show = _show;
    }
    
    @Override
    public void Draw(Timer gameTime,Graphics2D graphic)
    {
        if(show == true)
        {
            for (int i = 0; i <  _sprite.length; i++)
            {
                _sprite[i].Draw(gameTime,graphic);
            }
        }
    }
            
}
